<?php

class Chat_model extends CI_Model
{
    //上传图片
    public function uploadAvatar()
    {
        $this->load->database();

        $this->db->trans_start();

        $data = [
            'uid'        => $_POST['uid'],
            'submit_time'=> date('Y-m-d H:i:s',time()),
            'status'     => 1,
        ];

        $basedir = FCPATH . 'public/upload/avatar';

        $res = uploadImageCommon($_FILES['image'],$basedir);

        if ($res['ec'] == 400)
        {
            $this->db->close();
            displayJson(400,$res['em']);
        }

        $res['url'] = str_replace("\\", "/", $res['url']);

        $real_url   = substr($res['url'],strpos($res['url'],'public')-1);

        $data['image'] = $real_url;

        $this->db->insert('verify_log', $data);

        $this->db->trans_complete();

        if ($this->db->trans_status() === FALSE) {
            $this->db->close();
            displayJson(400,$this->db->_error_message());
        }

        $this->db->close();

        //sendEmail($this);

        displayJson(200,'投稿成功！');
    }

}